﻿using System;
using System.Collections.Generic;
using System.Text;

namespace UtilityToolsCollect.ObjectsLibrary.ProcessManage
{
    public struct ProcessTask:IEquatable<ProcessTask>,IEqualityComparer<ProcessTask>
    {
        public string ProcessPathOrName;
        public string? Arguments;
        public Action<string?>? OutputReceived;
        public Action<string?>? ErrorReceived;
        public Action<ProcessShell>? OnClossed;
        public Encoding? Encoding;
        public bool EnableDefaultSearch;

        public ProcessTask(string processPathOrName, string? arguments=null, Action<string?>? outputReceived=null, Action<string?>? errorReceived = null, 
            Action<ProcessShell>? onClossed = null, Encoding? encoding = null, bool enableDefaultSearch=false)
        {
            ProcessPathOrName = processPathOrName;
            Arguments = arguments;
            OutputReceived = outputReceived;
            ErrorReceived = errorReceived;
            OnClossed = onClossed;
            Encoding = encoding;
            EnableDefaultSearch = enableDefaultSearch;
        }
        
        public void Set(string processPathOrName, string? arguments = null, Action<string?>? outputReceived = null, Action<string?>? errorReceived = null,
            Action<ProcessShell>? onClossed = null, Encoding? encoding = null, bool enableDefaultSearch = false)
        {
            ProcessPathOrName = processPathOrName;
            Arguments = arguments;
            OutputReceived = outputReceived;
            ErrorReceived = errorReceived;
            OnClossed = onClossed;
            Encoding = encoding;
            EnableDefaultSearch = enableDefaultSearch;
        }


        public bool Equals(ProcessTask other) => other.ProcessPathOrName == ProcessPathOrName || other.Arguments == Arguments ||
            other.OutputReceived == OutputReceived || other.ErrorReceived == ErrorReceived || other.OnClossed == OnClossed ||
            other.Encoding == Encoding || other.EnableDefaultSearch == EnableDefaultSearch;
        public override bool Equals(object? obj) => Equals(obj is null ? null : (ProcessTask)obj);
        public override int GetHashCode() => base.GetHashCode();
        public override string ToString()=> $"{ProcessPathOrName}{Arguments}";
        public bool Equals(ProcessTask x, ProcessTask y) => x.Equals(y);
        public int GetHashCode(ProcessTask obj) => obj.GetHashCode();
    }
}
